@extends('default.layouts.companyPublic')

@section('title', '企业账户中心')
@section('headcss')
    @parent
    <link rel="stylesheet" type="text/css" href="{{asset('/default/css/company/myOrderList.css')}}">
@endsection
@section('rightcon')
    <div class="right">
        <!--菜单-->
        <div class="jright">
            <div class="content">
                <div class="jobtitle">
                    <div class="tithead">
                        <ul>
                            <li><a href="{{ route('myOrder.index') }}">我的套餐</a></li>
                            <li class="active"><a href="{{ route('myOrder.list') }}">我的定单</a></li>
                            <li><a href="{{ url('company/member_records') }}">会员记录</a></li>
                            @if(!empty(auth()->guard('company')->user()->stop_number))
                                <li><a href="{{ url('company/start_stop') }}">会员启停</a></li>
                            @endif
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="rightContain">
            <div class="note"><i></i><span>我的订单</span></div>
            {{--菜单列表--}}
            <div class="orderMune">
                <ul>
                    <li>我的套餐订单</li>
                </ul>
            </div>
            {{--提示--}}
            <div class="tip">
                <span class="icon"><img src="{{ asset("/default/images/company/tip.png") }}"> </span>
                <span class="content">
                    <p><em>小提示</em></p>
                    <p>订单自创建日期起，超过15天没有完成支付，系统将会自动将订单取消</p>
                </span>
            </div>
            {{--订单列表--}}
            <ul class="list bg">
                <li class="list1">订单内容</li>
                <li class="list2">支付方式</li>
                <li class="list3">
                    <select name="orderStats" id="orderStats">
                        <option value="">订单状态</option>
                        <option value="0">未支付</option>
                        <option value="2">已支付</option>
                        <option value="1">已取消</option>
                    </select>
                </li>
                <li class="list4">金额</li>
                <li class="list5">操作</li>
            </ul>
            @if(count($MyOrder) > 0)
                @foreach($MyOrder as $v)
                    <ul class="list baseLine">
                        <li class="list1">
                            <p>
                                {{--商户订单号与阿里支付商户号--}}
                                @if(!empty(Site::get('weiXinPayMCHID')) || !empty(Site::get('aLiPayPartner')))
                                    <a href="{{ route("myOrder.pay",['id'=>$v->id,'stats' => 2]) }}" target="_blank">{{ $v->vip_name }}</a>
                                    <em>(下单时间：{{ $v->created_at }})</em>
                                @else
                                    <a class="link" href="{{ route("WebContent",['contactus']) }}" target="_blank">{{ $v->vip_name }}</a>
                                    <em>(下单时间：{{ $v->created_at }})</em>
                                @endif
                            </p>
                        </li>
                        <li class="list2">{{ $v->myOrderWithCollOptions->opt_name or '' }}</li>
                        <li class="list3">{{ $v->payStats }}</li>
                        <li class="list4"><em>￥{{ $v->money }}</em></li>
                        <li class="list5">
                            @if($v->stats == 1)
                                <em class="cancel">已取消</em>
                            @elseif($v->stats == 2)
                                <em class="success">支付成功</em>
                            @else
                                {{--商户订单号与阿里支付商户号--}}
                                @if(!empty(Site::get('weiXinPayMCHID')) || !empty(Site::get('aLiPayPartner')))
                                    <em><a href="{{ route("myOrder.pay",['id'=>$v->id,'stats' => 0]) }}" target="_blank">支付</a></em>
                                    <em><a class="delete">取消<input type="hidden" value="{{ $v->id }}"></a></em>
                                @else
                                    <em><a class="link" href="{{ route("WebContent",['contactus']) }}" target="_blank">支付</a></em>
                                @endif
                            @endif
                        </li>
                    </ul>
                @endforeach
                <div class="page_list">
                    {!! $MyOrder->links() !!}
                </div>
            @else
                <div class="noData">暂无定单</div>
            @endif
        </div>
    </div>
@endsection
@section('footerjs')
    @parent
    <script type="text/javascript">
        //支付状态列表排序
        $("#orderStats").change(function(){
           location.href = "{{ route("myOrder.list") }}?stats="+$(this).val();
        });
        //如果生成新定单，弹出支付页面
        @if(!empty($VipPackage))
            layer.open({
                type: 1,
                title: '',
                skin: 'layui-layer-rim', //加上边框
                area: ['720px', '460px'], //宽高
                content: "<div id='payPage'></div>", //

                success: function(layero, index){
                    @if(!empty($VipPackage))
                        html = '<div class="payPage">'
                            +'<form name="payForm" id="payForm" action="{{ route("myOrder.toPay") }}" method="post">'
                            +' {{ csrf_field() }}'
                            +'<input type="hidden" name="orderId" value="{{ $VipPackage->orderId }}">'
                            +'<input type="hidden" name="money" value="{{ $VipPackage->money }}">'
                            +'<div class="note"><i></i><span>我的订单</span></div>'
                            +'<div class="current">已选套餐：<span><i></i>{{ $VipPackage->vipname or '' }}</span></div>'
                            +'<div class="icon"><img src="{{ asset("/default/images/company/up.png") }}"></div>'
                            +'<div class="info">'
                            +'<p>'
                            +'<span>套餐天数：<em>{{ $VipPackage->vip_days or '' }}</em>(天)</span>'
                            +'<span>套餐积分：<em>{{ $VipPackage->vip_integral + $VipPackage->integral }}</em>(分)</span>'
                            +'</p>'
                            +' <p>'
                            +'<span>套餐职位数：<em class="second">{{ $VipPackage->vip_post_number or '' }}</em>(个)</span>'
                            +'<span>套餐简历数：<em class="second">{{ $VipPackage->vip_resume_number + $VipPackage->resume_number }}</em>(份)</span>'
                            +'</p>'
                            +'</div>'
                            +'<div class="payType">'
                            +'<em>支付方式：</em>'
                            +'<input type="radio" name="payType" id="payType1" checked value="15">'
                            +'<label for="payType1">'
                            +'<img src="{{ asset('/default/images/company/pay_alipay.png') }}">'
                            +'</label>'
                            +'<input type="radio" name="payType" id="payType2" value="16">'
                            +'<label for="payType2">'
                            +'<img src="{{ asset('/default/images/company/pay_wxpay.png') }}">'
                            +'</label>'
                            +' </div>'
                            +'<div class="money">支付金额：<em>{{ $VipPackage->money }}</em>元</div>'
                            +'<div class="button" id="button">'
                            +'<input type="button" id="toPay" value="立即支付" onclick="aliPay()">'
                            +'</div>';
                    @else
                        html = '<div class="rightContain">该套餐已下架</div>';
                    @endif

                    $("#payPage").html(html);

                    //支付宝按钮
                    $("#payType1").click(function(){
                        $("#button").html('<input type="button" id="toPay" value="立即支付" onclick="aliPay()">');
                    });

                    //微信按钮
                    $("#payType2").click(function(){
                        $("#payForm").attr('target','_self');
                        $("#button").html('<input type="button" id="toMpPay" value="立即支付">');
                        //微信支付处理
                        $("#toMpPay").click(function(){
                            layer.open({
                                type: 1,
                                title: '微信支付扫一扫',
                                skin: 'layui-layer-rim', //加上边框
                                area: ['330px', '340px'], //宽高
                                content: "<div id='mpPayPng'><img src='{{ route("myOrder.toPay").'?orderId='.$VipPackage->orderId.'&payType=16' }}' width='280' height='280'></div>",

                                end:function(){
                                    layer.confirm('套餐充值成功?', {
                                            btn: ['是的', '遇到点问题'] //按钮
                                        },
                                        function(){//success
                                            window.location.reload();
                                        },
                                        function(){//false
                                            @if(!empty($CrmUser->withService))
                                                 @if(!empty($CrmUser->withService->phone))
                                                    html = "<p class='crmInfo'>客服：{{ $CrmUser->withService->worker_name }}</p>"
                                                    +"<p class='crmInfo'>座机号：{{ $CrmUser->withService->phone }}</p>";
                                                layer.open({
                                                    type: 1,
                                                    title: '您的专属客服信息',
                                                    skin: 'layui-layer-rim', //加上边框
                                                    area: ['200px', '100px'], //宽高
                                                    content: html, //禁滚动条
                                                    success: function(layero, index){
                                                    },
                                                    end:function(){}//点击完成事件后,显示内容后续操作
                                                });
                                            @endif
                                        @endif
                                    });
                                }//点击完成事件后,显示内容后续操作
                            });

                        });
                    });
                }
            });
        @endif

        //支付宝支付事件
        function aliPay(){
            $("#payForm").attr('target','_target');
            $("#payForm").submit();

            layer.confirm('套餐充值成功?', {
                    btn: ['是的', '遇到点问题'] //按钮
                },
                function(){//success
                    window.location.reload();
                },
                function(){//false
                    @if(!empty($CrmUser->withService))
                         @if(!empty($CrmUser->withService->phone))
                            html = "<p class='crmInfo'>客服：{{ $CrmUser->withService->worker_name }}</p>"
                            +"<p class='crmInfo'>座机号：{{ $CrmUser->withService->phone }}</p>";
                    layer.open({
                        type: 1,
                        title: '您的专属客服信息',
                        skin: 'layui-layer-rim', //加上边框
                        area: ['200px', '100px'], //宽高
                        content: html, //禁滚动条
                        success: function(layero, index){
                        },
                        end:function(){}//点击完成事件后,显示内容后续操作
                    });
                    @endif
                @endif
            });
        }
       //取消定单
        $(".list .list5 .delete").click(function(){
            id = $(this).find("input[type=hidden]").val();
            currnet = $(this);
            $.post("{{ route("myOrder.cancel") }}?id="+id , {
                '_token': "{{csrf_token()}}"
            }, function (data) {
                if (data.status == 0) {
                    currnet.parent().parent().html("<em class='cancel'>已取消</em></li>");
                    layer.msg(data.msg,{icon:6});
                } else {
                    layer.msg(data.msg,{icon:5});
                }
            });
        });
        //定单状态 提示
        @if(!empty(session('orderSuccess')))
            $(".content").find('p').eq(1).css('color','#21a74f');
            $(".content").find('p').eq(1).html("{{ session('orderSuccess') }}");
        @endif

        @if(!empty(session('orderErr')))
            $(".content").find('p').eq(1).css('color','#F0504E');
            $(".content").find('p').eq(1).html("{{ session('orderErr') }}");
        @endif

        //当前页  左边菜单小红条
        $("#leftnav_order").addClass("active");
    </script>
@endsection